import { GBox } from "../../../../../com/mui/containers/GBox";
import { GBoxDirection } from "../../../../../com/mui/containers/globalVariable/GBoxDirection";
import { DailyCompRewardInfo } from "../../../resource/info/DailyCompRewardInfo";
import { ObjectPool } from "../../../../../com/gengine/utils/pools/ObjectPool";
import { DegreeRwardItem } from "./DegreeRwardItem";
import { InvalidationType } from "../../../../../fl/core/InvalidationType";
type int = number;
//class DegreeRewardBody
    
    export  class DegreeRewardBody extends GBox
    {
        constructor()
        {
            super();
            direction = GBoxDirection.VERTICAL;
            verticalGap = 4;
            horizontalGap = 4;
            return;
        }

        public addItem(arg1: DailyCompRewardInfo): void
        {
            var loc1=ObjectPool.getObject(DegreeRwardItem);
            loc1.updateData(arg1);
            addChild(loc1);
            return;
        }

        public getItemNum(): int
        {
            return numChildren;
        }

        public getItemAt(arg1: int): DegreeRwardItem
        {
            if (arg1 < numChildren) 
            {
                return this.getChildAt(arg1) as DegreeRwardItem;
            }
            return null;
        }

        public getItemByIndex(arg1: int): DegreeRwardItem
        {
            var loc1=0;
            var loc3=null;
            var loc2=numChildren;
            while (loc1 < loc2) 
            {
                if ((loc3 = this.getItemAt(loc1)).info.index == arg1) 
                {
                    return loc3;
                }
                ++loc1;
            }
            return null;
        }

        public filterItem(arg1: int, arg2: int=0): void
        {
            this.getItemAt(arg1).filterColor(arg2);
            return;
        }

        public onGetRewardRes(arg1: int): void
        {
            var loc1=this.getItemByIndex(arg1);
            if (loc1) 
            {
                loc1.onGetRewardRes();
            }
            return;
        }

        public redraw(): void
        {
            layChildChanged = true;
            invalidate(InvalidationType.ALL);
            return;
        }

        public clear(): void
        {
            var loc1=null;
            while (numChildren > 0) 
            {
                loc1 = removeChildAt(0) as DegreeRwardItem;
                loc1.dispose();
                ObjectPool.disposeObject(loc1, DegreeRwardItem);
            }
            return;
        }

        protected /* override */ resetPosition(): void
        {
            var loc1=0;
            var loc5=null;
            var loc2=0;
            var loc3=0;
            var loc4=this.numChildren;
            loc1 = 0;
            while (loc1 < loc4) 
            {
                loc5 = this.getChildAt(loc1);
                if (loc1 % 2 != 0) 
                {
                    loc5.x = loc2 + horizontalGap;
                    loc5.y = loc3 + verticalGap;
                    loc3 = loc5.y + loc5.height;
                }
                else 
                {
                    loc5.x = horizontalGap;
                    loc5.y = loc3 + verticalGap;
                    loc2 = loc5.x + loc5.width;
                }
                ++loc1;
            }
            return;
        }

        public /* override */ get height(): number
        {
            return Math.ceil(numChildren / 2);
        }
    }
